import { Local } from '@/library/libs/storage'
import { GlobalConstant } from '@/library/constants/globalConstant'

/**
 * @function
 * @description 缓存token --> localStorage
 * @param {string} token - token
 * @returns {void} void
 */
const setToken = (token: string): void => Local.set(GlobalConstant.TOKEN_KEY, token, true)

/**
 * @function
 * @description 缓存refreshToken --> localStorage
 * @param {string} refreshToken - refreshToken
 * @returns {void} void
 */
const setRefreshToken = (refreshToken: string): void => Local.set(GlobalConstant.REFRESH_TOKEN_KEY, refreshToken, true)

/**
 * @function
 * @description 获取token --> localStorage
 * @returns {string|null} token
 */
const getToken = (): ReturnType<typeof Local.get> => Local.get(GlobalConstant.TOKEN_KEY, true)

/**
 * @function
 * @description 获取refreshToken --> localStorage
 * @returns {string|null} refreshToken
 */
const getRefreshToken = (): ReturnType<typeof Local.get> => Local.get(GlobalConstant.REFRESH_TOKEN_KEY, true)

/**
 * @function
 * @description 删除token --> localStorage
 * @returns {void} void
 */
const delToken = (): void => Local.remove(GlobalConstant.TOKEN_KEY)

/**
 * @function
 * @description 删除refreshToken --> localStorage
 * @returns {void} void
 */
const delRefreshToken = (): void => Local.remove(GlobalConstant.REFRESH_TOKEN_KEY)

/**
 * @function
 * @returns {void}
 */
const setRediectPath = (rp: string): void => Local.set(GlobalConstant.REDIECT_PATH, rp, true)

/**
 * @function
 * @returns {void}
 */
const getRediectPath = (): ReturnType<typeof Local.get> => Local.get(GlobalConstant.REDIECT_PATH, true)

export {
  setToken,
  setRefreshToken,
  getToken,
  getRefreshToken,
  delToken,
  delRefreshToken,
  setRediectPath,
  getRediectPath,
}
